package com.liyuhang;

import com.liyuhang.domain.User;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

import java.util.List;

public class Main {
    public static void main(String[] args) {
       SessionFactory sessionFactory=null;
        Session session=null;
        Configuration config = new Configuration().configure();
        StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
                .applySettings(config.getProperties());
        StandardServiceRegistry ssr=ssrb.build();
        sessionFactory=config.buildSessionFactory(ssr);
        session=sessionFactory.openSession();
        String hql = " from User ";
        Query query = session.createQuery(hql);
        List<User> users = query.list();
        for (User user : users) {
            System.out.println("username:"+user.getUsername());
            System.out.println("password:"+user.getPassword());
        }
    }
}
